Skip to content

🪲 [Fix]: Connect-GitHubApp no longer fails when only one installation exists#568

Merged
Marius Storhaug (MariusStorhaug) merged 3 commits intomainfrom
fix/567-connect-githubapp-single-installation
Apr 2, 2026
Merged

🪲 [Fix]: Connect-GitHubApp no longer fails when only one installation exists#568
Marius Storhaug (MariusStorhaug) merged 3 commits intomainfrom
fix/567-connect-githubapp-single-installation

Conversation

@MariusStorhaug
Copy link
Copy Markdown
Member

@MariusStorhaug Marius Storhaug (MariusStorhaug) commented Mar 29, 2026

Connect-GitHubApp now correctly connects to all available installations regardless of whether one or many exist. Previously, calling Connect-GitHubApp when the GitHub App had exactly one installation caused an AddRange failure, because PowerShell returned a single object instead of an array.

Fixed: Connecting with a single app installation

Connect-GitHubApp (with no filter parameters) no longer throws when your GitHub App has only one installation. The command now handles one, many, or zero installations identically.

This resolves the error:

Cannot convert argument "c", with value: "GitHubAppInstallation", for "AddRange" to type
"System.Collections.ICollection": "Cannot convert the "GitHubAppInstallation" value of type
"GitHubAppInstallation" to type "System.Collections.ICollection"."

Automation workflows (e.g., Distributor sync) that call Connect-GitHubApp without parameters will no longer fail on single-installation apps.

Technical Details

  • File: src/functions/public/Auth/Connect-GitHubApp.ps1
  • Root cause: ArrayList.AddRange() requires an ICollection. When Get-GitHubAppInstallation returns a single object, PowerShell does not wrap it in an array — the bare object doesn't implement ICollection, causing the call to throw.
  • Fix: Wrapped the call with the array sub-expression operator @() to guarantee an array is always passed: $selectedInstallations.AddRange(@(Get-GitHubAppInstallation -Context $Context))
  • This is a standard PowerShell idiom for preventing pipeline unrolling issues.

@MariusStorhaug Marius Storhaug (MariusStorhaug) marked this pull request as ready for review April 2, 2026 16:26
Copilot AI review requested due to automatic review settings April 2, 2026 16:26
@MariusStorhaug Marius Storhaug (MariusStorhaug) merged commit a0225f5 into main Apr 2, 2026
211 of 218 checks passed
@MariusStorhaug Marius Storhaug (MariusStorhaug) deleted the fix/567-connect-githubapp-single-installation branch April 2, 2026 16:27
@github-project-automation github-project-automation bot moved this from Todo to Done in GitHub PowerShell Module Apr 2, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes Connect-GitHubApp so it can connect to all GitHub App installations reliably when the app has exactly one installation, avoiding a runtime failure caused by passing a single object (instead of an ICollection) into ArrayList.AddRange().

Changes:

  • Wraps Get-GitHubAppInstallation with @() in the “connect to all installations” path to guarantee an array is passed to AddRange().

default {
Write-Verbose 'No target specified. Connecting to all installations.'
$selectedInstallations.AddRange((Get-GitHubAppInstallation -Context $Context))
$selectedInstallations.AddRange(@(Get-GitHubAppInstallation -Context $Context))
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regression coverage: this change fixes the single-installation case, but the current Pester suite appears to only exercise the default (no-parameter) path against whatever installations exist in the test environment, and doesn’t assert behavior when Get-GitHubAppInstallation yields exactly one object (the scenario that previously threw). Add a targeted test that forces a single-installation return (e.g., via a controlled fixture/mocking or a dedicated test app with exactly one installation) and asserts Connect-GitHubApp -PassThru does not throw and returns one context.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Fix Connect-GitHubApp AddRange failure when a single installation exists

2 participants